using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace YetAnotherTestProject
{
    public class Form1 : Form
    {
        public Form1()
        {
            this.Text = "Spike Solution 1";

            this.myFlow1 = new MyFlow();
            this.myFlow1.Dock = DockStyle.Fill;
            this.myFlow1.Padding = new Padding(15, 25, 15, 25);
            this.myFlow1.DoubleClick += new EventHandler(myFlow1_DoubleClick);

            this.Controls.Add(this.myFlow1);
        }

        void myFlow1_DoubleClick(object sender, EventArgs e)
        {
            foreach (string file in System.IO.Directory.GetFiles("../../Resources", "*.jpg"))
            {
                this.AddPictureBox(file);
            }
        }

        private void AddPictureBox(string pImage)
        {
            foreach (Control control in this.myFlow1.Controls)
            {
                if (control.Text == pImage)
                {
                    return;
                }
            }

            PictureBox picbox = new PictureBox();
            picbox.BorderStyle = BorderStyle.FixedSingle;
            picbox.Image = Image.FromFile(pImage);
            picbox.Size = new Size(128, 96);
            picbox.SizeMode = PictureBoxSizeMode.CenterImage;
            picbox.DoubleClick += new EventHandler(picbox_DoubleClick);
            picbox.Text = pImage;
            picbox.Visible = false;

            this.myFlow1.Controls.Add(picbox);
        }

        void picbox_DoubleClick(object sender, EventArgs e)
        {
            this.myFlow1.Controls.Remove((Control)sender);
        }

        private MyFlow myFlow1;
    }
}